package com.qijian.maindata.domain.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qijian.common.annotation.Excel;
import com.qijian.maindata.domain.ProcessOrder;
import com.qijian.maindata.domain.ProcessOrderUsers;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 工序工单对象
 *
 * @author qijian
 * @date 2021-10-09
 */

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class ProcessOrderNewVo extends ProcessOrder {

    @Excel(name = "项目编号", sort = 6)
    private String projectNo;
    @Excel(name = "产品名称", sort = 8)
    private String projectName;
    @Excel(name = "机台号", sort = 7)
    private String machineNo;
//    @Excel(name = "工单管理人", sort = 11)
//    private String nickName;
//    @Excel(name = "工单管理人所在车间", sort = 5)
//    private String deptName;

    private BigDecimal itemWeight;

    private String planSystem;
    private String planCode;
    private String itemCode;
    private String drawingNo;
    private String partNo;

    private String processTypeName;

    @TableField(exist = false)
    @JsonIgnore
    @Excel(name = "日期", sort = 2)
    @ApiModelProperty(value = "excel导出日期")
    private String workStartEndTime;

    public String getWorkStartEndTime() {
        if (this.getWorkStartTime() == null || this.getWorkEndTime() == null) return null;
        SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return fm.format(this.getWorkStartTime()) + " 至 " + fm.format(this.getWorkEndTime());
    }

    @JsonIgnore
    @TableField(exist = false)
    @Excel(name = "创建时间", dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 16)
    private Date excelCreateTime;


    public Date getExcelCreateTime() {
        return this.getCreateTime();
    }


    private Long wuId;


    /**
     * 用户ID
     */
    @NotNull(message = "作业人员不能为空")
//    @Excel(name = "用户ID")
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "用户ID")
    private Long userId;

    @Excel(name = "作业人员", sort = 13)
    @ApiModelProperty(value = "用户姓名")
    private String operName;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "部门ID")
    private Long deptId;

    @ApiModelProperty(value = "部门名称")
    @Excel(name = "作业人员所在车间", sort = 6)
    private String deptName;
    /**
     * 文件
     */
//    @Excel(name = "文件")
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "文件")
    private Long pictureId;

    /**
     * 工时
     */
    @NotNull(message = "工时不能为空")
    @Excel(name = "工单工时", sort = 15)
    @ApiModelProperty(value = "工单工时")
    private BigDecimal times;

    /**
     * 工时
     */
    @Excel(name = "实际工时", sort = 15)
    @ApiModelProperty(value = "实际工时")
    private BigDecimal actualTimes;

    /**
     * 工价
     */
    @NotNull(message = "工价不能为空")
    @Excel(name = "工价", sort = 16)
    @ApiModelProperty(value = "工价")
    private BigDecimal prices;

    /**
     * 接单时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "接单时间")
    private Date receiveTime;

    /**
     * 完工时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "完工时间")
    private Date reportTime;

    /**
     * 验收时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "验收时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 21)
    @ApiModelProperty(value = "验收时间")
    private Date checkTime;

    /**
     * 备注
     */
    @Excel(name = "备注", sort = 17)
    @ApiModelProperty(value = "备注")
    private String remark;

    /**
     * 状态（0-完成，1-待接单，2-已接单，3-停机待料）
     */
    @Excel(name = "状态", readConverterExp = "0=完成,1=待接单,2=已接单,3=停机待料,4=待验收", sort = 18)
    @ApiModelProperty(value = "状态（0-完成，1-待接单，2-已接单，3-停机待料）")
    private Integer status;

    @TableId
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "ID")
    private Long workId;

    /**
     * 关联项目
     */
    @NotNull(message = "关联项目不能为空")
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "关联项目")
    private Long projectId;


    /**
     * 所属工位
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "所属工位")
    private Long factoryId;

    /**
     * 来源
     */
    @ApiModelProperty(value = "来源")
    private String sourceId;

    /**
     * 工单编号
     */
    @Excel(name = "工单编号", sort = 1)
    @ApiModelProperty(value = "工单编号")
    private String workCode;

    /**
     * NCR编号
     */
    @Excel(name = "NCR编号",sort = 4)
    @ApiModelProperty(value = "NCR编号")
    private String ncrCode;

    /**
     * 派工类型
     */
    @NotNull(message = "派工类型不能为空")
    @Excel(name = "派工类型", dictType = "process_order_type",sort = 3)
    @ApiModelProperty(value = "派工类型")
    private String workType;

    /**
     * 物料ID
     */
    @ApiModelProperty(value = "物料ID")
    private Long itemId;

    /**
     * 物料名称
     */
    @NotNull(message = "物料不能为空")
    @Excel(name = "物料名称",sort = 9)
    @ApiModelProperty(value = "物料名称")
    private String itemName;

    /**
     * 工序ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "工序ID")
    private Long processId;

    /**
     * 工序名称
     */
    @NotNull(message = "工序不能为空")
    @Excel(name = "工序",sort = 10)
    @ApiModelProperty(value = "工序名称")
    private String processName;

    /**
     * 数量
     */
    @NotNull(message = "数量不能为空")
    @ApiModelProperty(value = "数量")
    private Integer workNumber;

    /**
     * 工序工时
     */
    @NotNull(message = "总工价不能为空")
    @Excel(name = "工时",sort = 13)
    @ApiModelProperty(value = "工序工时")
    private BigDecimal workTime;

    /**
     * 工序工价
     */
    @NotNull(message = "总工价不能为空")
    @Excel(name = "工价",sort = 14)
    @ApiModelProperty(value = "工序工价")
    private BigDecimal workCost;

    /**
     * 开始时间
     */
    @NotNull(message = "开始时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "开始时间")
    private Date workStartTime;

    /**
     * 结束时间
     */
    @NotNull(message = "结束时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "结束时间")
    private Date workEndTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "派单时间")
    private Date dispatchTime;

    /**
     * 是否外协
     */
    @ApiModelProperty(value = "是否外协")
    private Boolean isOut;

    @ApiModelProperty(value = "是否检验")
    private Boolean isCheck;

    @ApiModelProperty(value = "是否关闭")
    private Boolean isClose;


    @TableField(exist = false)
    private List<ProcessOrderUsers> users;

    @ApiModelProperty(value = "外协剩余数量")
    private Integer surplusNumber;

}
